<!Doctype html>
<html>
	<head>
		<title></title>
	</head>
	<body>
		<script type="text/javascript">

/*//单体模式
var funcitonGroup = {
	name : "kathy",
	method1 : function(){},
	init : function(){}
}

//or
var myGroup = function(){
	this.name= 'Darren';
	this.getName= function(){
		return this.name;
	}
	this.method1= function(){}
}
var myGroup1 = new myGroup();
console.log(myGroup1.getName());*/



/*
//简单工厂模式
var XMLHttpFactory = function(){};

XMLHttpFactory.createXMLHttp = function(){
	var XMLHttp = null;
	if(window.XMLHttpRequest){
		XMLHttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XMLHttp;
}

var AjaxHandler = function(){
	var XMLHttp = XMLHttpFactory.createXMLHttp();
}



//抽象工厂模式的使用方法就是先设计一个抽象类，这个类不能被实例化，只能用来派生子类，最后通过对子类的扩展实现工厂方法
var XMLHttpFactory = function(){};

XMLHttpFactory.prototype = {
	//如果真的要调用这个方法会抛出一个错误，它不能被实例化，只能用来派生子类
	createFactory : function(){
		throw new Error("this is an abstract class");
	}
}

var XHRHandler = function(){
	XMLHttpFactory.call(this);
}
XHRHandler.prototype = new XMLHttpFactory();
XHRHandler.prototype.constructor = XHRHandler;
//重新定义createFactory方法
XHRHandler.prototype.createFactory =  function(){
	var XMLHttp = null;
	if(window.XMLHttpRequest){
		XMLHttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XMLHttp;
}

*/




addEvent(element,'click',getBeerById);
function(e){
	var id= this.id;
	asyncRequest('GET','beer.url?id=' + id,function(resp){
		//Callback response
		console.log('Requested Beer:' + resp.responseText);
	});
}

addEvent(element, 'click', getBeerByIdBridge);
function getBeerByIdBridge (e) {
　　getBeerById(this.id, function(beer) {console.log('Requested Beer: '+beer);});
}
		</script>
	</body>
</html>